﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace CRConsult.Models
{
    public class empRepository
    {
        /// <summary>
        /// 获取员工列表
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public List<tb_Employee> getEmpList(int id)
        {
            using (LingHealEntities db = new LingHealEntities())
            {
                var items = db.tb_Employee.Where(i => i.EmpID == id);
                return items.ToList();
            }
        }

        /// <summary>
        /// 删除员工
        /// </summary>
        /// <param name="id"></param>
        public void delEmp(int id)
        {
            using (LingHealEntities db = new LingHealEntities())
            {
                db.DeleteObject(db.tb_Employee.Where(i=>i.EmpID==id));
                db.SaveChanges();
            }
        }

        /// <summary>
        /// 添加员工信息
        /// </summary>
        /// <param name="item"></param>
        public void insertEmp(tb_Employee item)
        {
            using (LingHealEntities db = new LingHealEntities())
            {
                db.AddTotb_Employee(item);
                db.SaveChanges();
            }
        }

        /// <summary>
        /// 更新员工信息
        /// </summary>
        /// <param name="item"></param>
        public void updateEmp(tb_Employee item)
        {
            using (LingHealEntities db = new LingHealEntities())
            {
                var originitem = db.tb_Employee.FirstOrDefault(i => i.EmpID == item.EmpID);
                originitem.EmpIntro = item.EmpIntro;
                originitem.EmpName = item.EmpName;
                originitem.EmpPrice = item.EmpPrice;
                originitem.EmpSort = item.EmpSort;
                originitem.EmpGroupID = item.EmpGroupID;
                originitem.EmpPhoto = item.EmpPhoto;
                db.SaveChanges();
            }
        }
    }
}